home *** CD-ROM | disk | FTP | other *** search
/ Best of www.BestZips.com (Collector's Edition) / Best of WWW.BESTZIPS.COM Collector's Edition (JCSM Shareware) (JCS Marketing).ISO / tutorial / adatu311.zip / VAX.ADA < prev   
Text File  |  1996-01-10  |  5KB  |  118 lines

  1. -- VAX.ADA   Ver. 3.11   10-JAN-1996   Copyright 1988-1996 John J. Herro
  2. --
  3. -- SOFTWARE INNOVATIONS TECHNOLOGY          http://members.aol.com/AdaTutor
  4. -- 1083 MANDARIN DR NE                      ftp://members.aol.com/AdaTutor
  5. -- PALM BAY FL 32905-4706
  6. --                                          johnherro@aol.com
  7. -- (407) 951-0233                           john.herro%374-38-2@satlink.oau.org
  8. --
  9. -- Compile this before compiling ADA_TUTR.ADA with VAX Ada.  See the first page
  10. -- of ADA_TUTR.ADA for more details.
  11. --
  12. package Custom_IO is
  13.    type Color is (Black, Red, Green, Yellow, Blue, Magenta, Cyan, White);
  14.    Foregrnd_Color   : Color := White;                 -- Default values in case
  15.    Backgrnd_Color   : Color := Black;                 -- ADA-TUTR finds no User
  16.    Border_Color     : Color := Black;                 -- File.
  17.    Fore_Color_Digit : Character := Character'Val(Color'Pos(Foregrnd_Color)+48);
  18.    Back_Color_Digit : Character := Character'Val(Color'Pos(Backgrnd_Color)+48);
  19.    Normal_Colors    : String(1 .. 10) := ASCII.ESC & "[0;3" &
  20.                               Fore_Color_Digit & ";4" & Back_Color_Digit & "m";
  21.    Clear_Scrn       : constant String := ASCII.ESC & "[H" & ASCII.ESC & "[2J";
  22.  
  23.    procedure Set_Border_Color (To   : in  Color);
  24.    procedure Get              (Char : out Character);
  25.    procedure Put              (Char : in  Character);
  26.    procedure Put              (Str  : in  String);
  27.    procedure Put_Line         (Str  : in  String);
  28.    procedure Get_Line         (Str  : out String; Last : out Natural);
  29.    procedure New_Line;
  30. end Custom_IO;
  31.  
  32. with Starlet, System; use Starlet, System;
  33. package body Custom_IO is
  34.    Chan : Starlet.Channel_Type;
  35.    IOSB : System.Unsigned_Quadword;
  36.    Stat : System.Unsigned_Longword;
  37.    procedure QIOW(Stat : out Unsigned_Longword; EFN : in Integer;
  38.         Chan : in Channel_Type; Func : in Short_Integer;
  39.         IOSB : out Unsigned_Quadword; ASTadr : in Integer; ASTPRM : in Integer;
  40.         P1 : in out String; P2, P3 : in Integer; P4 : in Unsigned_Quadword;
  41.         P5, P6 : in Integer);                   -- Pragma Interface is used for
  42.    pragma Interface(System_Library, QIOW);      -- compatibility with Ada 83.
  43.    pragma Import_Valued_Procedure(Internal => QIOW, External => "SYS$QIOW",
  44.         Parameter_Types => (Unsigned_Longword, Integer, Channel_Type,
  45.              Short_Integer, Unsigned_Quadword, Integer, Integer, String,
  46.              Integer, Integer, Unsigned_Quadword, Integer, Integer),
  47.         Mechanism => (Value, Value, Value, Value, Reference, Value, Reference,
  48.              Reference, Value, Reference, Reference, Reference, Reference));
  49.  
  50.    procedure Set_Border_Color(To : in Color) is
  51.       -- Dummy procedure for computers other than PCs.
  52.    begin
  53.       null;
  54.    end Set_Border_Color;
  55.  
  56.    procedure Get(Char : out Character) is
  57.       S : String(1 .. 1);
  58.    begin
  59.       QIOW(Stat, 0, Chan, 16#7A#, IOSB, 0, 0, S, 1, 0, (0,0), 0, 0);
  60.       Char := S(1);
  61.    end Get;
  62.  
  63.    procedure Put(Char : in Character) is
  64.    begin
  65.       Put(Char & "");
  66.    end PUT;
  67.  
  68.    procedure Put(Str : in String) is
  69.       S : String(Str'Range) := Str;
  70.    begin
  71.       QIOW(Stat, 0, Chan, 16#70#, IOSB, 0, 0, S, S'Length, 0, (0,0), 0, 0);
  72.    end PUT;
  73.  
  74.    procedure Put_Line(Str : in String) is
  75.    begin
  76.       Put(Str & ASCII.CR & ASCII.LF);
  77.    end Put_Line;
  78.  
  79.    procedure Get_Line(Str : out String; Last : out Natural) is separate;
  80.  
  81.    procedure New_Line is
  82.    begin
  83.       Put(ASCII.CR & ASCII.LF);
  84.    end New_Line;
  85. begin
  86.    Starlet.Assign(Stat, "TT:", Chan);
  87. end Custom_IO;
  88.  
  89. -- This procedure gets a string from the terminal, while allowing typing errors
  90. -- to be corrected.
  91. --
  92. separate (Custom_IO)
  93. procedure Get_Line(Str : out String; Last : out Natural) is
  94.    S     : String(Str'Range);                             -- Local copy of Str.
  95.    Char  : Character := ' ';                    -- One character from keyboard.
  96.    Place : Integer   := Str'First;     -- Position of next available character.
  97. begin
  98.    while Char /= ASCII.CR loop                   -- CR signifies end of string.
  99.       Get(Char);                                          -- Get one character.
  100.       if Char = ASCII.CR then
  101.          New_Line;                       -- Give new line at end of the string.
  102.       elsif Char = ASCII.BS or Char = ASCII.DEL then
  103.          if Place > Str'First then        -- Ignore BS/DEL when string is null.
  104.             Put(ASCII.BS & ' ' & ASCII.BS);   -- Erase last char. from display.
  105.             Place := Place - 1;               -- Remove last char. from string.
  106.          end if;
  107.       elsif Place > Str'Last then    -- Beep when length of string is exceeded.
  108.          Put(ASCII.BEL);
  109.       else
  110.          Put(Char);                                -- Echo the character typed.
  111.          S(Place) := Char;                      -- Add character to the string.
  112.          Place := Place + 1;
  113.       end if;
  114.    end loop;
  115.    Str(Str'First .. Place - 1) := S(Str'First .. Place - 1);
  116.    Last := Place - 1;
  117. end Get_Line;
  118.